<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <button onclick="clickCode();">同意授权</button>
</body>
<script src="../static/js/jquery. min.js" th:src="@{/js/jquery.min.js}"></script>
<script>
    function clickCode(){
        $.ajax({
            url: 'http://everythingisok.free.idcfengye.com/templates/auth/preAuth',
            type: 'POST',
            dataType: "json",
            data: {},
            success: function(res){
                if(res.status==200){
                   console.log("授权中")
                }else{
                    console.log("授权中.....")
                }
            },
            error: function(){
                alert('服务器发生错误！');
            }
        });

    }
    var code = GetQueryString('code');
    if(code!=null){
        $.ajax({
            url: 'http://everythingisok.free.idcfengye.com/templates/auth/login_by_weixin',
            type: 'POST',
            dataType: "json",
            data: {
                code:code
            },
            success: function(res){
                if(res.errno==0){
                    console.log("授权中.....")
                    var mode = res.data;
                    var urlMode = "&usrOpenid="+mode.usrOpenid;
                     urlMode = urlMode+"&usrImg="+mode.usrImg;
                     urlMode = urlMode+"&usrSex="+mode.usrSex;
                     urlMode = urlMode+"&usrlv="+mode.usrLv;
                     urlMode = urlMode+"&usrMoney="+mode.usrMoney;
                     urlMode = urlMode+"&usrNextMoney="+mode.usrNextMoney;
                    window.location.href="http://7s2xmw.natappfree.cc?id="+mode.id+urlMode;
                }else{
                    console.log(res);
                    return false;
                }
            },
            error: function(){
                alert('服务器发生错误！');
            }
        });

    }
    function GetQueryString(name){
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return unescape(r[2]); return null;
    }
</script>
</html>